#include "APP_Message.h"

int main(int argc, char const *argv[])
{
    // char str[] = "abc";
    // char hex[8] = {0};
    // char str1[4] = {0};
    // char hex1[] = "646566";
    // log_info("字符数组 -> 十六进制字符数组\n");
    // APP_COM_Bytes_To_HexStr(hex,str,3);
    // log_info("%s 转化结果: %s\n",str,hex);
    // log_info("十六进制字符数组 -> 字符数组\n");
    // APP_COM_HexStr_To_Bytes(hex1,str1,6);
    // log_info("%s 转化结果: %s\n",hex1,str1);  

    // char arr[5] = {0};
    // memcpy(arr,"aaabbb",4);
    // log_info("arr: %s\n",arr); 

    log_info("bytes -> Message\n");
    char bt[] = {0x01,0x02,0x04,0xFE,0xEF,'s','u','d','a','\0'};
    // Message msg = {.conn_type = 1,.id_len = 2,.msg_len = 4,.payload = "suda"};
    Message *msg = APP_Bytes_To_Message(bt);
    log_info("type: %d id_len: %d msg_len: %d payload: %s\n",msg->conn_type,msg->id_len,msg->msg_len,msg->payload);
    log_info("Message -> json\n");
    char* json_str = APP_Message_To_Json(msg);
    log_info("%s\n",json_str);

    log_info("json -> Message\n");
    Message * msg1 = APP_Json_To_Message(json_str);
    log_info("type: %d id_len: %d msg_len: %d payload: %s\n",msg1->conn_type,msg1->id_len,msg1->msg_len,msg1->payload);
    log_info("id[0] = %02x id[1] = %02x\n",(unsigned char)msg1->payload[0],(unsigned char)msg1->payload[1]);

    log_info("Message -> json\n");
    char* json_str1 = APP_Message_To_Json(msg1);
    log_info("%s\n",json_str1);

    log_info("Message -> bytes\n");
    char *str = APP_Message_To_Bytes(msg1);
    log_info("%02x%02x%s\n",(unsigned char)str[0],(unsigned char)str[1],(char*)(str+2));
    return 0;
}

